﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace DungeonGenerator.Tests
{
    using System.Linq;

    using FluentAssertions;

    [TestClass]
    public class TestRandomizerTests
    {
        [TestMethod]
        public void NextBoolDistribution()
        {
            var rnd = new TestRandomizer(0);
            var trues = 0;
            var attempts = int.MaxValue / 1000;
            for (var i = 0; i < attempts; i++)
            {
                if (rnd.NextBool()) trues++;
            }
            double distribution =((double)trues) / attempts;
            distribution.Should().BeInRange(0.49, 0.51);
        }

        [TestMethod]
        public void NextIsExclusive()
        {
            var rnd = new TestRandomizer(0);
            const int maxAttempts = int.MaxValue / 1000;
            const int minValue = 0;
            const int maxValue = 2;
            var q=Enumerable.Range(0, maxAttempts).Select(i => rnd.Next(minValue, maxValue));
            q.Should().NotContain(maxValue);
            q.Should().Contain(minValue);
            q.Should().Contain(maxValue - 1);
        }

        [TestMethod]
        public void NextInclusiveIsInclusive()
        {
            var rnd = new TestRandomizer(0);
            var maxAttempts = int.MaxValue / 1000;
            var maxValue = 2;
            var minValue = 0;
            var q = Enumerable.Range(0, maxAttempts).Select(i => rnd.NextInclusive(0, maxValue));
            q.Should().Contain(maxValue);
            q.Should().Contain(minValue);
            
        }
    }
}
